dic1 = {'Tom':21,'Bob':18,'Jack':23,'Ana':20}
dic2 = {'李雷':21,'韩梅梅':18,'小明':23,'小红':20}

n = int(input())

sorted_dic1_keys = sorted(dic1.keys())
sorted_dic2_items = sorted(dic2.items(), key=lambda x: x[1])

output_dic1 = {k: dic1[k] for k in sorted_dic1_keys[:n]}
output_dic2 = dict(sorted_dic2_items[:n])

print(output_dic1.values())
print(output_dic2.keys())
